package com.oa.android.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.oa.android.R;
import com.oa.android.activity.AboutActivity;
import com.oa.android.activity.InfoActivity;
import com.oa.android.activity.SaveServiceActivity;
import com.oa.android.utils.UConstants;
import com.oa.android.utils.Util;

/**
 * wo
 * Created by zouqh on 2016/6/10.
 */
public class MyFragment extends Fragment implements View.OnClickListener {

    View myView;
    private LinearLayout info;
    private RelativeLayout change,update;
    private TextView exit;
    private TextView name;
    private Util util;


    //重写setMenuVisibility方法，不然会出现叠层的现象
    @Override
    public void setMenuVisibility(boolean menuVisibile) {
        super.setMenuVisibility(menuVisibile);
        if (this.getView() != null) {
            this.getView().setVisibility(menuVisibile ? View.VISIBLE : View.GONE);

        }
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

        myView = inflater.inflate(R.layout.my_layout, container, false);
        info=(LinearLayout)myView.findViewById(R.id.info);
        change=(RelativeLayout)myView.findViewById(R.id.change);
        update=(RelativeLayout)myView.findViewById(R.id.update);
        exit=(TextView)myView.findViewById(R.id.exit);
        name=(TextView)myView.findViewById(R.id.name);
        name.setText(UConstants.EmpName+"");
        info.setOnClickListener(this);
        change.setOnClickListener(this);
        update.setOnClickListener(this);
        exit.setOnClickListener(this);
        util=new Util(getActivity());
        return myView;
    }

    @Override
    public void onClick(View v) {
        Intent intent = new Intent();
        switch (v.getId()){
            case R.id.info:
                startActivity(new Intent(getActivity(),InfoActivity.class));
                break;
            case R.id.change:
                intent.setClass(getActivity(), SaveServiceActivity.class);
                intent.putExtra("type","2");
                startActivity(intent);
                break;
            case R.id.update:
                startActivity(new Intent(getActivity(),AboutActivity.class));
                break;
            case R.id.exit:
                util.setUser(UConstants.TRUENAME,"","0");
                getActivity().finish();

                break;
        }
    }
}
